﻿using System;
using System.Collections.Generic;
using Godot;

namespace kemocard.Scripts.Story;

public static class StoryFactory
{
    private static readonly Dictionary<string, Type> StoryTypeDict = new()
    {
        { "tutorial", typeof(TutorialStory) },
        { "rogue", typeof(RogueStory) }
    };

    public static void RegisterStory(string id, Type type)
    {
        if (type.IsSubclassOf(typeof(StoryScript)) || type == typeof(StoryScript))
        {
            StoryTypeDict[id] = type;
        }
    }

    public static StoryScript CreateStory(string id)
    {
        if (StoryTypeDict.TryGetValue(id, out var value))
        {
            return Activator.CreateInstance(value) as StoryScript;
        }

        GD.PrintErr($"无法找到故事, ID:{id}");
        return null;
    }
}